package com.siashan.toolkit.oss.qiniu.core;

import com.qiniu.storage.Region;

/**
 * 七牛云区域属性
 *
 * @author  siashan
 * @since   v1.0.1
 **/
public enum QiniuOssRegionEnum {

    /**
     * 华东
     */
    HUADONG("huadong", Region.huadong()),
    /**
     * 华北
     */
    HUABEI("huabei", Region.huabei()),
    /**
     * 华南
     */
    HUANAN("huanan", Region.huanan()),
    /**
     * 北美
     */
    BEIMEI("beimei", Region.beimei()),
    /**
     * 东南亚
     */
    XINJIAPO("xinjiapo", Region.xinjiapo());

    private String code;
    private Region region;

    QiniuOssRegionEnum(String code, Region region) {
        this.code = code;
        this.region = region;
    }


    /**
     * 解析region值
     *
     * @param code  配置文件维护的region值
     * @return region对象
     */
    public static Region parseRegion(String code) {
        if (null == code || "".equals(code)) {
            return null;
        }
        try {
            QiniuOssRegionEnum enumm = Enum.valueOf(QiniuOssRegionEnum.class, code);
            return enumm.getRegion();
        } catch (Exception e) {
            return null;
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }


    public static void main(String[] args) {

    }
}
